package com.shoeshopping.utils.pc;


import java.util.ArrayList;
import java.util.List;

import org.hibernate.Session;

import com.shoeshopping.entity.DeliveryAddress;
import com.shoeshopping.entity.User;

public class Test {
	
	public static void main(String[] args) {
		
		/*
		BeanFactory factory = new ClassPathXmlApplicationContext("applicationContext.xml");
		GetIntoCartDao getIntoCartDao = (GetIntoCartDao) factory.getBean("getIntoCartDao");
		getIntoCartDao.save(new User());*/
		
		
		Session session = HibernateUtils.getSession();
		/*
		session.beginTransaction();
		String hql = "from User u where u.username = " + "'pc'";
		
		Query query = session.createQuery(hql);
		List list = query.list();
		session.getTransaction().commit();
		
		Iterator it = list.iterator();
		while(it.hasNext()) {
			User u = (User) it.next();
			DeliveryAddress da = u.getAddresses().get(0);
			System.out.println(da.getAddress());
		}
		*/
		
		User u = new User();
		u.setUsername("pc");
		u.setBalance(100);
		u.setPassword("000000");
		u.setEmail("123456@qq.com");
		
		DeliveryAddress da = new DeliveryAddress();
		da.setAddress("住址");
		da.setName("bababab");
		da.setPhone("1323123132");
		da.setUser(u);
		List<DeliveryAddress> list = new ArrayList<DeliveryAddress>();
		list.add(da);
		u.setAddresses(list);
		
		session.beginTransaction();
		session.save(u);
		session.save(da);
		session.getTransaction().commit();
		
		/*
		Goods g = new Goods();
		g.setName("kobe");
		g.setDetails("blahblahblah");
		g.setColor("red");
		g.setImgPath("/abc");
		g.setPrice("500.50");
		g.setRest(10);
		g.setType("favouriate");
		
		session.beginTransaction();
		session.save(g);
		session.getTransaction().commit();
		*/
		
		
	}
	
}
